﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Acoris.Rendering
{
    /// <summary>
    /// 表示一个渲染树
    /// </summary>
    public class RenderTree
    {
        internal RootLayout rootElement;

        /// <summary>
        /// 初始化渲染树
        /// </summary>
        internal RenderTree() { }


        #region GetElementsByType

        public VisualElement[] GetElementsByType(Type type)
        {
            var visualElementList = new List<VisualElement>();

            GetElementsByType(visualElementList, rootElement, type);

            if(visualElementList.Count > 0)
            {
                var visualElementArray = visualElementList.ToArray();
                return visualElementArray;
            }
            return null;
        }

        internal static void GetElementsByType<T>(IList<VisualElement> visualElementList,IEnumerable<T> element, Type type)
            where T : VisualElement
        {
            if(element == null)
            {
                return;
            }

            if (element.GetType() == type)
            {
                visualElementList.Add((VisualElement)element);
            }

            foreach (var child in element)
            {
                if (child is IEnumerable<VisualElement>)
                {
                    GetElementsByType(visualElementList, (IEnumerable<VisualElement>)child, type);
                }
            }
        }

        #endregion

        #region GetElementsByClassName


        internal static void GetElementsByClassName(IList<VisualElement> visualElementList,VisualElement element,int classId)
        {
        }

        #endregion
    }
}
